package com.java47.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.java47.mapper.FlowerMapper;
import com.java47.pojo.Flower;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class FlowerServiceImpl implements  FlowerService{

    @SuppressWarnings("all")
    @Autowired
    private FlowerMapper fmapper;

    @Override
    public Flower selectOne(Integer fid) {
        return fmapper.selectOne(fid);
    }

    @Override
    public Page showPage(Integer index, Integer size) {
        Page<Object> page = PageHelper.startPage(index,size);
        List<Flower> list = fmapper.selectAll();
        return page;
    }

    @Override
    @Transactional
    public boolean update(Map<String, Object> map) {
        int num = 0;
        if (map.keySet().iterator().hasNext()) {
            if (map.keySet().contains("add")) {
                num = fmapper.add((Flower) map.get("add"));
            } else if (map.keySet().contains("del")) {
                num = fmapper.del((Integer) map.get("del"));
            } else if (map.keySet().contains("update")) {
                num = fmapper.update((Flower) map.get("update"));
            }
        }
        return num > 0 ? true : false;
    }

    @Override
    public List<Flower> select(Flower f) {
        return fmapper.select(f);
    }
}
